home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / Bonus / Plasmatech / ptscp_examples.exe / %MAINDIR% / Examples / NetworkTree / CBuilder / FMain.cpp next >
Encoding:
C/C++ Source or Header  |  2001-08-31  |  2.0 KB  |  61 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl\vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include "FMain.h"
  6. //---------------------------------------------------------------------------
  7. #pragma link "UPTFrame"
  8. #pragma link "UPTShellControls"
  9. #pragma link "UPTTreeList"
  10. #pragma resource "*.dfm"
  11. TFrmMain *FrmMain;
  12. //---------------------------------------------------------------------------
  13. /*
  14.  The technique used to determine which nodes are "Computer" nodes is find which image is
  15.  used for computers and simple check a node's image against that value. It should be
  16.  possible to use the SHGetDataFromIDList function to check what type a node is, but
  17.  that function seems very unreliable.
  18. */
  19. __fastcall TFrmMain::TFrmMain(TComponent* Owner)
  20.     : TForm(Owner)
  21. {
  22.   try {
  23.     char sz[MAX_COMPUTERNAME_LENGTH+1];
  24.     DWORD siz = sizeof(sz);
  25.     GetComputerName( sz, &siz );
  26.     if (strlen(sz) == 0)
  27.       throw new Exception( "This computer is not present on the network." );
  28.     FComputerIndex = ShellGetIconIndexFromPath("\\\\"+AnsiString(sz),0);
  29.   }
  30.   catch( Exception* e ) {
  31.     Application->ShowMainForm = false;
  32.     Application->HandleException(e);
  33.     Application->Terminate();
  34.   }
  35. }
  36. //---------------------------------------------------------------------------
  37. void __fastcall TFrmMain::PTShellTree1Change(TObject *Sender, TTreeNode *Node)
  38. {
  39.   if (Node->ImageIndex == FComputerIndex)
  40.     SetFrameText( Node->Text );
  41.   else
  42.     SetFrameText( "" );
  43. }
  44. //---------------------------------------------------------------------------
  45. void __fastcall TFrmMain::SetFrameText( AnsiString aName )
  46. {
  47.   if (aName.Length() == 0) {
  48.     CompLabel->Caption = "<Not a computer>";
  49.     CompLabel->Color = clRed;
  50.   }
  51.   else {
  52.     CompLabel->Caption = aName;
  53.     CompLabel->Color = clGreen;
  54.   }
  55. }
  56. //---------------------------------------------------------------------------
  57. void __fastcall TFrmMain::Exit1Click(TObject *Sender)
  58. {
  59.   Close();
  60. }
  61. //---------------------------------------------------------------------------